package com.property.manage.controller.village;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.system.SysSet;
import com.property.manage.model.village.DownVo;
import com.property.manage.model.village.Village;
import com.property.manage.service.system.SysSetService;
import com.property.manage.service.village.VillageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Api(tags = "小区管理")
@RestController
@RequestMapping("/village")
@AllArgsConstructor
@Validated
public class VillageController {
    @Autowired
    private VillageService villageService;
    @Autowired
    private SysSetService sysSetService;


    @ApiOperation("小区列表")
    @GetMapping("/page")
    public CustomPage<Village> userPage(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "请输入当前页码") Long pageNo,
                                        @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "请输入每页条数") Long pageSize,
                                        @ApiParam("小区") @RequestParam(value = "name", required = false) String name){
        return villageService.villagePage(pageNo, pageSize, name);
    }

    @ApiOperation("小区类型")
    @GetMapping("/type")
    public List<SysSet> type(){
        return sysSetService.getSysSets(SysSet.TYPE_VILLAGE);
    }

    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(@RequestParam(value = "type")@NotNull(message = "类型不能为空") Integer type,@RequestParam(value = "propertyMoney")@NotNull(message = "物业基数不能为空") BigDecimal propertyMoney,
                    @RequestParam(value = "rent",required = false) BigDecimal rent,@RequestParam(value = "name") @NotNull(message = "小区名称不能为空")String name

    ){
       villageService.add(type,propertyMoney,rent,name);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public void update(@RequestParam(value = "id")@NotNull(message = "id不能为空") Integer id,
                       @RequestParam(value = "type")@NotNull(message = "类型不能为空") Integer type,
                       @RequestParam(value = "propertyMoney")@NotNull(message = "物业基数不能为空") BigDecimal propertyMoney,
                       @RequestParam(value = "rent", required = false) BigDecimal rent,
                       @RequestParam(value = "name") @NotNull(message = "小区名称不能为空")String name){
       villageService.update(id,type,propertyMoney,rent,name);
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public void delete(@ApiParam("小区id") @RequestParam("id") @NotNull(message = "小区id为空") Integer id){
        villageService.delete(id);
    }
    @ApiOperation("下拉框")
    @GetMapping("/down")
    @ResponseBody
    public List<DownVo> down(){
        return villageService.down();
    }
}
